
<HTML>
<HEAD>
<TITLE>The JavaScript Source:  Generators:  HTML2XHTML</TITLE>
<META HTTP-EQUIV="The JavaScript Source" CONTENT = "no-cache">
<META NAME="description" CONTENT="The H2X converter generates a well-formed XHTML string from an

HTML DOM object. H2X could be used in content management

systems, online WYSIWYG HTML editors or any other application to

produce well formed XHTML 1.0 code.">
<META NAME="date" CONTENT="2004-09-29">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="V. Smolin">
<META NAME="section" CONTENT="Generators">
<!-- This script and many more are available free online at -->

<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Original:  V. Smolin -->

<!-- Web Site:  http://html2xhtml.richarea.com -->

<script language="JavaScript" src="html2xhtml.js"></script>



<script language="JavaScript">



// this variables are necessary for the demo only



//encoding parameters

var lang = "en";

var encoding = "iso-8859-1";



//determine IE version

		var ie_data = navigator.userAgent.match(/MSIE ([0-9|\.]+)/);

var ie_version = null;

	if (ie_data) {

		ie_version = parseFloat(ie_data[1]);

	}



	var can_parse = false;



// this variables are necessary for the demo only



		function write2iframe(){



	var page_mode = get_page_mode();

//*



//get html text to convert

		var text2set = document.getElementById('html2convert_source').value;

	if (!page_mode) text2set = '<html><body>'+text2set+'</body></html>';



//write the text to iframe to access it later via dom object

		if (document.all) {

	var iframe_doc = html2convert.document;

		} else {

			var iframe_doc = document.getElementById('html2convert').contentWindow.document;

		}



		if (document.all && ie_version < 5.5) {

		//ie5.0 could generates onload event earlier then loading is actually finished

				iframe_doc.onload = setTimeout('parse_iframe()', 1);

		}



		iframe_doc.open();

		iframe_doc.write(text2set);

		iframe_doc.close();



		}



//convert html to xhtml and write to destination textarea

		function parse_iframe(){

	if (!can_parse) return;



	var page_mode = get_page_mode();



//determine source dom object

		if (document.all) {

	var iframe_doc = html2convert.document;

		} else {

			var iframe_doc = document.getElementById('html2convert').contentWindow.document;

		}



		if (page_mode) {

			var source_obj = iframe_doc;

		} else {

			if (document.all) {

				var source_obj = iframe_doc.body; //html fragment ie

			} else {

				var source_obj = iframe_doc.documentElement; //html fragment mozilla

			}

		}



		var xhtml_content = get_xhtml(source_obj, lang, encoding);



		if (document.all) {

			html2convert_result.value = xhtml_content;

		} else {

			document.getElementById('html2convert_result').value = xhtml_content;

		}

		}



//allow to convert if the whole document is loaded only

		function init(){

	can_parse = true;

		}



		function get_page_mode(){

			if (document.all) {

				return page_mode.checked;

			} else {

				return document.getElementById('page_mode').checked;

			}



		}



		</script>


				</HEAD>

				<BODY BGCOLOR=#ffffff vlink=#0000ff onLoad="init()">

				<BR>
				<center>
				<!--#include virtual="/_includes/topad.html" -->
				<BR>
				<BR>
				<!--#include virtual="/_includes/sidead-top.html" -->
				<basefont size=3>
				<FONT SIZE="+2" FACE="Helvetica,Arial">
				<A HREF="http://javascript.internet.com" TARGET="_top"><FONT COLOR="#0000FF"><b>Home</b></font></A>
				<img src="http://javascript.internet.com/img/arrow.gif" height=13 width=7 border=0 alt="}">
				<A HREF="./" TARGET="_top"><font color="#FF0000"><b>Generators</b></font></A>
				<img src="http://javascript.internet.com/img/arrow.gif" height=13 width=7 border=0 alt="}">
				<FONT COLOR="#006666"><b>HTML2XHTML</b></font></font>
				<BR>
				<BR>
				<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
				<tr><td><font FACE="helvetica,arial,geneva">
				<br>
				<br>
				<!-- Description --><!--content_start-->
				The H2X converter generates a well-formed XHTML string from an

				HTML DOM object. H2X could be used in content management

				systems, online WYSIWYG HTML editors or any other application to

				produce well formed XHTML 1.0 code.
				<hr>
				</td></tr>
				</table>
				<!-- Demonstration -->
				<!-- This script and many more are available free online at -->

				<!-- The JavaScript Source!! http://javascript.internet.com -->

				<!-- Original:  V. Smolin -->

				<!-- Web Site:  http://html2xhtml.richarea.com -->

				<!--<iframe id="html2convert" onload="parse_iframe();" style="width:1px;height:1px;display:snone;visibility:hidden">&nbsp; </iframe><br />-->

				html:<br />

				<textarea id="html2convert_source" rows="13" cols="80">

				<STYLE type=text/css>.top {

			BORDER-RIGHT: #33ff33 1px solid; BORDER-TOP: #33ff33 1px solid; BORDER-LEFT: #33ff33 1px solid; BORDER-BOTTOM: #33ff33 1px solid; BACKGROUND-COLOR: #c8c4bb

}

		.bottom {

			BORDER-RIGHT: #ff3333 1px solid; BORDER-TOP: black 0px solid; BORDER-LEFT: #ff3333 1px solid; BORDER-BOTTOM: #ff3333 1px solid; BACKGROUND-COLOR: #d4d0c8

}

		.nav:hover {

			FONT-WEIGHT: bold; FONT-SIZE: 10px; COLOR: #666666; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: underline

}

		.nav {

			FONT-WEIGHT: bold; FONT-SIZE: 10px; COLOR: #666666; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none

}

		.text {

			FONT-SIZE: 10px; COLOR: #333333; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

		</STYLE>



				<P><FONT size=6><FONT face=Verdana><STRONG><FONT color=#6633ff><FONT color=#ff6633>R</FONT>ich <FONT color=#ff6633>E</FONT>ditor</FONT>!</STRONG></FONT></FONT><BR>

				<TABLE style="WIDTH: 100%" borderColor=#6600ff cellSpacing=0 cellPadding=0 bgColor=#ccffff border=2>

				<TBODY>

				<TR>

				<TD><IMG style="WIDTH: 259px; HEIGHT: 32px" src="http://www.richarea.com/demo_rich/files/apache_pb.gif"></TD>

				<TD>

				<UL>

				<LI><FONT color=#cc6633><FONT face="Courier New" size=2>Create <EM>images</EM>, <EM>tables</EM>; right click to edit it!</FONT> </FONT>

				<LI><FONT face="Courier New" size=2><FONT color=#cc6633>Use RE in your forms instead <STRONG>textarea</STRONG></FONT></FONT></LI></UL></TD></TR></TBODY></TABLE></P>

				<P><SPAN class=nav>Full <SPAN class=header>stylesheet</SPAN> support available!</SPAN><SPAN class=special> Now RE works with <SPAN class=header>FLASH</SPAN>!</SPAN></P>

				</textarea>

				<br />

				xhtml:<br />

				<textarea id="html2convert_result" rows="13" cols="80">

				</textarea>

				<br />

				<iframe id="html2convert" onload="parse_iframe();" style="width:1px;height:1px;display:snone;visibility:hidden">&nbsp; </iframe><br />

				<input id="page_mode" type="checkbox" value="1"><label for="page_mode">convert whole page</label></input>&nbsp;

		<input type="button" onclick="write2iframe();" value="html => xhtml" />
				<P>
				<P>
				<a name="source">
				<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
				<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>The JavaScript Source:  BG Effects:  HTML2XHTML</b>
				<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s).  The script is yours!!!
				<br><br></font></td></tr>
				<tr><td BGCOLOR=yellow ALIGN=CENTER>
				<form NAME="copy">

				<DIV align="center">
				<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
		<INPUT TYPE="text" NAME="total" VALUE="Script Size:  5.98 KB" size=24>
				</DIV>

				<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- THREE STEPS TO INSTALL HTML2XHTML:



				1.  Copy the coding into the HEAD of your HTML document

				2.  Add the onLoad event handler into the BODY tag

				3.  Put the last coding into the BODY of your HTML document  --&gt;



		&lt;!-- STEP ONE: Paste this code into the HEAD of your HTML document  --&gt;



		&lt;HEAD&gt;



		&lt;!-- This script and many more are available free online at --&gt;

		&lt;!-- The JavaScript Source!! http://javascript.internet.com --&gt;

		&lt;!-- Original:  V. Smolin --&gt;

		&lt;!-- Web Site:  http://html2xhtml.richarea.com --&gt;

		&lt;script language="JavaScript" src="html2xhtml.js"&gt;&lt;/script&gt;



		&lt;script language="JavaScript"&gt;



// this variables are necessary for the demo only



//encoding parameters

				var lang = "en";

		var encoding = "iso-8859-1";



//determine IE version

				var ie_data = navigator.userAgent.match(/MSIE ([0-9|\.]+)/);

		var ie_version = null;

		if (ie_data) {

			ie_version = parseFloat(ie_data[1]);

}



		var can_parse = false;



// this variables are necessary for the demo only



				function write2iframe(){



			var page_mode = get_page_mode();

//*



//get html text to convert

				var text2set = document.getElementById('html2convert_source').value;

		if (!page_mode) text2set = '&lt;html&gt;&lt;body&gt;'+text2set+'&lt;/body&gt;&lt;/html&gt;';



//write the text to iframe to access it later via dom object

				if (document.all) {

			var iframe_doc = html2convert.document;

} else {

			var iframe_doc = document.getElementById('html2convert').contentWindow.document;

}



		if (document.all && ie_version &lt; 5.5) {

		//ie5.0 could generates onload event earlier then loading is actually finished

				iframe_doc.onload = setTimeout('parse_iframe()', 1);

}



		iframe_doc.open();

		iframe_doc.write(text2set);

		iframe_doc.close();



}



//convert html to xhtml and write to destination textarea

				function parse_iframe(){

			if (!can_parse) return;



		var page_mode = get_page_mode();



//determine source dom object

				if (document.all) {

			var iframe_doc = html2convert.document;

} else {

			var iframe_doc = document.getElementById('html2convert').contentWindow.document;

}



		if (page_mode) {

			var source_obj = iframe_doc;

} else {

			if (document.all) {

			var source_obj = iframe_doc.body; //html fragment ie

} else {

			var source_obj = iframe_doc.documentElement; //html fragment mozilla

}

}



		var xhtml_content = get_xhtml(source_obj, lang, encoding);



		if (document.all) {

			html2convert_result.value = xhtml_content;

} else {

			document.getElementById('html2convert_result').value = xhtml_content;

}

}



//allow to convert if the whole document is loaded only

				function init(){

			can_parse = true;

}



		function get_page_mode(){

			if (document.all) {

			return page_mode.checked;

} else {

			return document.getElementById('page_mode').checked;

}



}



		&lt;/script&gt;



		&lt;/HEAD&gt;



		&lt;!-- STEP TWO: Insert the onLoad event handler into your BODY tag  --&gt;



		&lt;BODY onLoad="init()"&gt;



		&lt;!-- STEP THREE: Copy this code into the BODY of your HTML document  --&gt;



		&lt;!-- This script and many more are available free online at --&gt;

		&lt;!-- The JavaScript Source!! http://javascript.internet.com --&gt;

		&lt;!-- Original:  V. Smolin --&gt;

		&lt;!-- Web Site:  http://html2xhtml.richarea.com --&gt;

		&lt;!--&lt;iframe id="html2convert" onload="parse_iframe();" style="width:1px;height:1px;display:snone;visibility:hidden"&gt;&nbsp; &lt;/iframe&gt;&lt;br /&gt;--&gt;

		html:&lt;br /&gt;

		&lt;textarea id="html2convert_source" rows="13" cols="80"&gt;

		&lt;STYLE type=text/css&gt;.top {

			BORDER-RIGHT: #33ff33 1px solid; BORDER-TOP: #33ff33 1px solid; BORDER-LEFT: #33ff33 1px solid; BORDER-BOTTOM: #33ff33 1px solid; BACKGROUND-COLOR: #c8c4bb

}

		.bottom {

			BORDER-RIGHT: #ff3333 1px solid; BORDER-TOP: black 0px solid; BORDER-LEFT: #ff3333 1px solid; BORDER-BOTTOM: #ff3333 1px solid; BACKGROUND-COLOR: #d4d0c8

}

		.nav:hover {

			FONT-WEIGHT: bold; FONT-SIZE: 10px; COLOR: #666666; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: underline

}

		.nav {

			FONT-WEIGHT: bold; FONT-SIZE: 10px; COLOR: #666666; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none

}

		.text {

			FONT-SIZE: 10px; COLOR: #333333; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

}

		&lt;/STYLE&gt;



		&lt;P&gt;&lt;FONT size=6&gt;&lt;FONT face=Verdana&gt;&lt;STRONG&gt;&lt;FONT color=#6633ff&gt;&lt;FONT color=#ff6633&gt;R&lt;/FONT&gt;ich &lt;FONT color=#ff6633&gt;E&lt;/FONT&gt;ditor&lt;/FONT&gt;!&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;

		&lt;TABLE style="WIDTH: 100%" borderColor=#6600ff cellSpacing=0 cellPadding=0 bgColor=#ccffff border=2&gt;

		&lt;TBODY&gt;

		&lt;TR&gt;

		&lt;TD&gt;&lt;IMG style="WIDTH: 259px; HEIGHT: 32px" src="http://www.richarea.com/demo_rich/files/apache_pb.gif"&gt;&lt;/TD&gt;

		&lt;TD&gt;

		&lt;UL&gt;

		&lt;LI&gt;&lt;FONT color=#cc6633&gt;&lt;FONT face="Courier New" size=2&gt;Create &lt;EM&gt;images&lt;/EM&gt;, &lt;EM&gt;tables&lt;/EM&gt;; right click to edit it!&lt;/FONT&gt; &lt;/FONT&gt;

		&lt;LI&gt;&lt;FONT face="Courier New" size=2&gt;&lt;FONT color=#cc6633&gt;Use RE in your forms instead &lt;STRONG&gt;textarea&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;

		&lt;P&gt;&lt;SPAN class=nav&gt;Full &lt;SPAN class=header&gt;stylesheet&lt;/SPAN&gt; support available!&lt;/SPAN&gt;&lt;SPAN class=special&gt; Now RE works with &lt;SPAN class=header&gt;FLASH&lt;/SPAN&gt;!&lt;/SPAN&gt;&lt;/P&gt;

		&lt;/textarea&gt;

		&lt;br /&gt;

		xhtml:&lt;br /&gt;

		&lt;textarea id="html2convert_result" rows="13" cols="80"&gt;

		&lt;/textarea&gt;

		&lt;br /&gt;

		&lt;iframe id="html2convert" onload="parse_iframe();" style="width:1px;height:1px;display:snone;visibility:hidden"&gt;&nbsp; &lt;/iframe&gt;&lt;br /&gt;

		&lt;input id="page_mode" type="checkbox" value="1"&gt;&lt;label for="page_mode"&gt;convert whole page&lt;/label&gt;&lt;/input&gt;&nbsp;

		&lt;input type="button" onclick="write2iframe();" value="html =&gt; xhtml" /&gt;



		&lt;p&gt;&lt;center&gt;

		&lt;font face="arial, helvetica" size"-2"&gt;Free JavaScripts provided&lt;br&gt;

		by &lt;a href="http://javascriptsource.com"&gt;The JavaScript Source&lt;/a&gt;&lt;/font&gt;

		&lt;/center&gt;&lt;p&gt;



		&lt;!-- Script Size:  5.98 KB --&gt;</textarea><br><font FACE="helvetica,arial,geneva"><a href="http://javascript.internet.com/link-us.html">Did you use this script?&nbsp;&nbsp;Do you like this site?&nbsp;&nbsp;Please link to us!</a></font></td></tr>

				</table>
				</form>
				<!--content_stop-->

				<!--#include virtual="/_footer.html" -->




